/**
 * 
 */
package com.orange.modules.dao.expert;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.orange.dbhelp.DbHelper;
import com.orange.modules.entity.expert.AuthExamExpertMap;

/**
 * @author gaogs
 *
 * 2016-12-1
 */
@Repository
public class AuthExpertExamMapRepository {
	
	@Resource(name = "dbHelper")
	private DbHelper dbHelper;
	
	@Autowired
	private AuthExpertExamMapDao authExamExpertMapDao ;
	
	/**
	 * 批量保存专家与试题关系
	 * @param list
	 */
	public void saveAuthExamExpertMapInfos(List<AuthExamExpertMap> list){
		authExamExpertMapDao.save(list);
	}
	
	/**
	 * 批量删除专家试题
	 * @param list
	 */
	public void deleteAuthExamExpertMapInfos(List<AuthExamExpertMap> list){
		authExamExpertMapDao.delete(list);
	}
	
	/**
	 * 查询组内相应专业下试题
	 * @param taskId
	 * @param subject
	 * @return
	 * @throws SQLException 
	 */
	public List<AuthExamExpertMap> queryAuthExamExpertMapByTaskAndSubject(String groupId ,String taskId,String subject) throws SQLException{
		String sql="SELECT ee.p_id as pid ,ee.s_expert_id as expertId ,ee.s_exam_id as examId,ee.s_group_id as groupId ," +
				" ee.s_create_time as createTime " +
				" FROM t_auth_exam_expert_map as ee " +
				" LEFT JOIN t_auth_exam as ww ON ee.s_exam_id=ww.p_id " +
				" WHERE ee.s_group_id=? AND ww.s_task_id=? " +
				" ";
		if(StringUtils.isNotBlank(subject)){
			sql+="AND ww.s_subject='"+subject+"'";
		}
		List<AuthExamExpertMap> list=dbHelper.getBeanList(sql, AuthExamExpertMap.class, groupId,taskId);
		return list;
	}

	
	/**
	 * 查询组内专家相应专业下试题
	 * @param taskId
	 * @param subject
	 * @return
	 * @throws SQLException 
	 */
	public List<AuthExamExpertMap> queryAuthExamExpertMapByTaskAndExpertId(String groupId ,String taskId,String expertId) throws SQLException{
		String sql="SELECT ee.p_id as pid ,ee.s_expert_id as expertId ,ee.s_exam_id as examId,ee.s_group_id as groupId ," +
				" ww.s_name as examName,ww.s_file_url as fileUrl ," +
				" ee.s_create_time as createTime " +
				" FROM t_auth_exam_expert_map as ee " +
				" LEFT JOIN t_auth_exam as ww ON ee.s_exam_id=ww.p_id " +
				" WHERE ee.s_group_id=? AND ww.s_task_id=? AND ee.s_expert_id=?" +
				" ";
		List<AuthExamExpertMap> list=dbHelper.getBeanList(sql, AuthExamExpertMap.class, groupId,taskId,expertId);
		return list;
	}
	
	
	
	
	
}
